package cn.xumaoyang.user.controller;

import cn.xumaoyang.basic.exception.BusinessException;
import cn.xumaoyang.basic.util.AjaxResult;
import cn.xumaoyang.user.service.IVerifycodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 注册使用验证码。
 */
@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;

    @PostMapping("/smsCode")
    //前端传来的参数，可以使用map来接收，方便使用key值来对应valve，随便定义一个接收名。
    public AjaxResult smsCode(@RequestBody Map<String,String> params ){
        try {
            //传递到后面进行操作。
            verifycodeService.sendSmsCode(params);
            return new AjaxResult();
        }catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }
        catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙请稍后重新操作");
        }
    }
}
